<?php
function acc_lock($key) {
    $lockPath = $_SERVER['DOCUMENT_ROOT'] . '/accHestia/tmp/';
    $fn = md5(__FILE__ . $key);
    $hdl_file = fopen($lockPath . $fn . '.lock', "w+");

    if (flock($hdl_file, LOCK_EX)) { //LOCK_EX:独占锁定  LOCK_NB:锁定时不堵塞
    } else {
        throw new Exception("Error locking file!");;
    }
    return $hdl_file;
}

function acc_unlock($hdl_file) {
    flock($hdl_file, LOCK_UN);
    fclose($hdl_file); 
}
?>
